﻿using INTEX.DataBase;
using ReflectionStudio.Core.Events;
using System;
using System.Collections.Generic;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.ComponentModel;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for SETUPABON.xaml
    /// </summary>
    public partial class TICC_HRSTAMM
    {

        public TICC_HRSTAMM()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VICC_HRSTAMM();
            this.DataContext = MV;
            InitializeComponent();
        }
         public override void NewCommand(object sender, RoutedEventArgs e)
        { 
            try
            {
                if (!IsNew)
                {
                    IsNew = true;
                    KRS = "";
                    return;
                }
                if (KRS == "")
                    return;
                dwData = TBMain.NewRow();
                TMV.SetUpNewRow(ref dwData);
                LFD = VSDDAT.SD22.GETNEXT("0022", "  ", "HRSEQ", 1);
                dwData["COMPANY"] = app.company;
                dwData["ROWNID"] = LFD;
                dwData["USERID"] = KRS;
                TMV.Insert(dwData);
                vwMaster.View.MoveCurrentToFirst();
                base.NewCommand(sender, e);
                KRS = "";
                IsNew = false;
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        public override void EditCommand(object sender, RoutedEventArgs e)
        {
            base.EditCommand(sender, e);
        }
        public override void QueryCommand(object sender, RoutedEventArgs e)
        {
            dwData = TBMain.NewRow();
            SResult = TMV.QIHR_1(dwData);
            MergeData(SResult, true);
        }
        public override void CopyCommand(object sender, RoutedEventArgs e)
        {
            dwData = TBMain.NewRow();
            dwData.ItemArray = dwMaster.ItemArray;
            LFD = VSDDAT.SD22.GETNEXT("0022", "  ", "HRSEQ", 1);
            dwData["COMPANY"] = app.company;
            dwData["ROWNID"] = LFD;
            TMV.Insert(dwData);
            vwMaster.View.MoveCurrentToFirst();
            base.CopyCommand(sender, e);
        }
        
        public override void SaveCommand(object sender, RoutedEventArgs e)
        {
            if (dwMaster == null)
                return;
            TMV.UpdateICC_HRSTAMM(dwMaster, 0);
            base.SaveCommand(sender, e);
        }

        public override void DeleteCommand(object sender, RoutedEventArgs e)
        {
            if (dwMaster == null)
                return;
            TMV.DeleteICC_HRSTAMM(dwMaster, 1); 
            string filter = "ROWNID='" + dwMaster["ROWNID"].ToString() + "'";
            DataRow[] rows = TBMain.Select(filter);
            vwMaster.View.MoveCurrentTo(-1);
            foreach (DataRow row in rows)
            {
                row.Delete();
            }
            TBMain.AcceptChanges();
            base.DeleteCommand(sender, e);
        }
     
    }
}
